#pragma once

#include <vector>
#include <map>
#include <unordered_map>

#include "noncopyable.h"
#include "channel.h"
// moduo库的多路事件分发器的核心IO复用模块

/**
 * 这是一个抽象类 
 */
class Poller{
public:
    using ChannelList = std::vector<Channel*>;

    Poller(EventLoop *loop);
    virtual ~Poller() = default;

    // 给所有IO复用保留的统一接口
    // activateChannels 传出参数
    virtual TimeStamp poll(int timeout, ChannelList* activateChannels) = 0;
    virtual void updateChannel(Channel* channel) = 0;
    virtual void removeChannel(Channel* channel) = 0;

    // 判断channel是否在poller里面
    bool hasChannel(Channel* channel) const;

    // 通过该接口获得poller的具体实现
    static Poller* newDefaultPoller(EventLoop *loop);

protected:
    using ChannelMap = std::unordered_map<int, Channel*>;
    ChannelMap channels_;

private:
    // 自己所在的eventloop
    EventLoop* ownerLoop_;
};